/**
 * @Description: 初始化单元测试配置及代码
 * @author Beon
 * @date 2021/1/14
*/
import * as childProcess from 'child_process';
import * as fs from 'fs';

export {
    createEmpty,
    buildTsc
};

/**
 * 创建新环境
 */
async function createEmpty (path: string): Promise<void> {
    await buildTsc();

    await fs.mkdirSync(path, { recursive: true });

    await childProcess.spawnSync('npm', ['init', '--force', '--yes'], { cwd: path, shell: true });

    await childProcess.spawnSync('git', ['init'], { cwd: path, shell: true });

    await childProcess.spawnSync('git', ['add', '.'], { cwd: path, shell: true });

    await childProcess.spawnSync('git', ['commit', '-m', '第一次测试添加'], { cwd: path, shell: true });
}

/**
 * 创建新的运行环境
 * @returns {Promise<void>}
 */
async function buildTsc(): Promise<void> {
    await childProcess.spawnSync('tsc --build ./test/tsconfig.json', { shell: true });
}
